<?php
//this file process all the books 
include('auth.php');
//the following code includes the mysql connect code
include 'connect.php';

function mysql_insert($table, $inserts) {
    $values = array_map('mysql_real_escape_string', array_values($inserts));
    $keys = array_keys($inserts);
       
    return mysql_query('INSERT INTO `'.$table.'` (`'.implode('`,`', $keys).'`) VALUES (\''.implode('\',\'', $values).'\')');
}

// this code looks for all POST vars 
$authlast = $_GET['lname'];
$authfirst = $_GET['fname'];
$grade = $_GET['grade'];
$year = $_GET['year'];
$stamp = time();


mysql_insert('patrons', array(
    'fname' => $authfirst,
    'lname' => $authlast,
	'grade' => $grade,
	'year' => date("Y"),
	'timestamp' => $stamp,

));

$sql_select = "SELECT * FROM patrons WHERE timestamp = '$stamp'";
$fetch = mysql_query($sql_select);
$book_fetch = mysql_fetch_array($fetch);
$name = $book_fetch['fname'];
$lname = $book_fetch['lname'];
$barcode = $book_fetch['code'];
$grade = $book_fetch['grade'];
$year = date("Y");
header("Location: /olms/?p=patron/index.php&status=added&fname=$name&Year=$year&Grade=$grade&barcode=$barcode&lname=$lname&author_first=$author_first&callnum=$call");
?>